package org.sbbs.app.demo.schedule;

import java.util.Date;
import java.util.logging.Logger;

import org.sbbs.app.demo.model.DemoSysDbLog;
import org.sbbs.app.demo.service.DemoSysDbLogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;


/*@Service*/
public class TestService{

    private static final Logger logger_c = Logger.getLogger( TestService.class.getName());  
    @Autowired
    DemoSysDbLogManager demoSysDbLogManager;
    public void testServiceMethod()  
    {  DemoSysDbLog log = new DemoSysDbLog();
         Date date = new Date();  
         log.setLogMsg( "demo message at " + date.toString() );
         
         Authentication au = SecurityContextHolder.getContext().getAuthentication();
         if(au!=null)
             log.setOperator(((UserDetails) au.getPrincipal()).getUsername());
         else
             log.setOperator( "no user login" );
         
         log.setLogTime( date );
         this.demoSysDbLogManager.addLog( log );
         logger_c.info( "test service method invoked: " + date.toString());  
    }  

}